package actions;

import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Term;

import ecomp.architecture.EcompArch;
import ecomp.models.LocalWorldModel;

@SuppressWarnings("serial")
public class afastado_n_cells extends DefaultInternalAction{
	
	EcompArch arch;
	LocalWorldModel localWorldModel;
	
	@Override
	public Object execute(TransitionSystem ts, Unifier un, Term[] args)
			throws Exception {
		
		arch = (EcompArch) ts.getUserAgArch();
		localWorldModel = arch.localWorldModel;
		Term NCells = args[0];
		Term Tagx = args[1];
		Term Tagy = args[2];
		Term x = args[3];
		Term y = args[4];
		
		// Unfold terms
		int agx = (int) ((NumberTerm)Tagx).solve();
		int agy = (int) ((NumberTerm)Tagy).solve();
		int xValue = (int) ((NumberTerm)x).solve();
		int yValue = (int) ((NumberTerm)y).solve();
		int valueNCells = (int) ((NumberTerm)NCells).solve();
		
		int cells = (int)(Math.sqrt(Math.pow(agx - xValue,2) + Math.pow(agy - yValue,2)));
		
		return cells == valueNCells;
	}
}